<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Lime Unit Tests - lime.parser.TMX</title>
<script src="../../closure/closure/goog/base.js"></script>
<script>
  goog.require('goog.testing.MockClock');
  goog.require('goog.testing.jsunit');
  goog.require('goog.testing.recordFunction');
  goog.require('goog.testing.PropertyReplacer');
  goog.require('lime.parser.TMX');
</script>
</head>
<style>
</style>
<body>
    
<script>

var stubs = new goog.testing.PropertyReplacer();

function shouldRunTests() {
  return true;
}

function setUpPage(){
    mockClock = new goog.testing.MockClock(1);
}

function tearDownPage(){
    mockClock.uninstall();
}

function tearDown() {
    stubs.reset();
}
function setUp(){
}


function testLoadTMXMap() {
	
    var tmx = new lime.parser.TMX('assets/area02.tmx');
	
	assertNotNull('tmp object', tmx);

}

function testMainInfosTMXMap() {
	var tmx = new lime.parser.TMX('assets/area02.tmx');
	assertEquals('map orientation','orthogonal',tmx.orientation);
	assertEquals('map version',1.0,tmx.version);
	assertEquals('map width',40,tmx.width);
	assertEquals('map height',15,tmx.height);
	assertEquals('map tilewidth',32,tmx.tilewidth);
	assertEquals('map tileheight',32,tmx.tileheight);
	assertEquals('map properties count',1,tmx.properties.length);
}

function testTilesTMXMap() {
	var tmx = new lime.parser.TMX('assets/area02.tmx');
	assertEquals('tilesset count',2,tmx.tilesets.length);
	assertEquals('tilesset 1 first gid',1,tmx.tilesets[0].firstgid);
	assertEquals('tilesset 2 first gid',141,tmx.tilesets[1].firstgid);
	
	tilewidthcount0 = parseInt(tmx.tilesets[0].image.width / tmx.tilesets[0].tilewidth);
	tileheightcount0 = parseInt(tmx.tilesets[0].image.height / tmx.tilesets[0].tileheight);
	tilewidthcount1 = parseInt(tmx.tilesets[1].image.width / tmx.tilesets[1].tilewidth);
	tileheightcount1 = parseInt(tmx.tilesets[1].image.height / tmx.tilesets[1].tileheight);
	
	tilescount = tilewidthcount0 * tileheightcount0 + tilewidthcount1 * tileheightcount1;
	assertEquals('tilescount',tilescount,tmx.tiles.length);
}

function testTilesPropertiesTMXMap() {
	var tmx = new lime.parser.TMX('assets/area02.tmx');

	assertEquals('tile 0',0,tmx.tiles[0].properties.length);
	assertEquals('tile 1',1,tmx.tiles[1].properties.length);
	assertEquals('tile 2',1,tmx.tiles[2].properties.length);
	assertEquals('tile 3',0,tmx.tiles[3].properties.length);
}

function testLayerTMXMap() {
	var tmx = new lime.parser.TMX('assets/area02.tmx');

	assertEquals('layer count',2,tmx.layers.length);
}

function testObjectsTMXMap() {
	var tmx = new lime.parser.TMX('assets/area02.tmx');

	assertEquals('objects count',24,tmx.objects.length);
	assertEquals('object 0 properties count',2,tmx.objects[0].properties.length);
	assertEquals('object 2 properties count',0,tmx.objects[2].properties.length);
}

function testErrorTMXMap() {
	var error = false;
	try {
    var tmx = new lime.parser.TMX('assets/Notsupportedmap.tmx');
	} catch(e) {
		error = true;
	}
	assertEquals('error ?', true, error);
}

function testErrorTMXMap2() {
	var error = false;
	try {
		var tmx = new lime.parser.TMX('assets/area02_base64.tmx');
	} catch(e) {
		error = true;
	}
	assertEquals('error ?', true, error);
}

</script>
</body>
</html>
